/**
 * 邮箱
 * @param {*} s
 */
export function isEmail (s) {
  return /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(s)
}

/**
 * 手机号码
 * @param {*} s
 */
export function isMobile (s) {
  return /^1[0-9]{10}$/.test(s)
}

/**
 * 电话号码
 * @param {*} s
 */
export function isPhone (s) {
  return /^([0-9]{3,4}-)?[0-9]{7,8}$/.test(s)
}

/**
 * URL地址
 * @param {*} s
 */
export function isURL (s) {
  return /^http[s]?:\/\/.*/.test(s)
}


/**
 * 新建课程考研年份，计算近五年
 */
export function nearlyFiveYears () {
  let now = new Date();
  let currYear = now.getFullYear();
  let years = [];
  for(var i=1; i<=5; i++){
    years.push(currYear+i+'')
  }
  return years;
}

/**
 * 时分转换为时间戳 s
 */
export function HMtimestamp (time) {
  let s = 0;
  let hour = time.split(':')[0];
  let min = time.split(':')[1];
  let sec = time.split(':')[2];
  s = Number(hour * 3600) + Number(min * 60) + Number(sec);
  return s;
}

/**
 * 时间戳转换为时分
 */
export function timestampHM (time) {
  let hours = parseInt((time % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  let minutes = parseInt((time % (1000 * 60 * 60)) / (1000 * 60));
  let seconds = parseInt((time % (1000 * 60)) / 1000);
  hours = hours < 10 ? ('0' + hours) : hours;
  minutes = minutes < 10 ? ('0' + minutes) : minutes;
  seconds = seconds < 10 ? ('0' + seconds) : seconds;
  return `${hours}:${minutes}:${seconds}`;
}

/**
 * 时间转换为时间戳
 */
export function timeToTimestamp (time) {
  if(!time){
    return;
  }
  let date = new Date(time);
  return date.getTime();
}

/**
 * 时间戳转换为时间
 */
export function timestampToTime (timestamp, type) {
  if(!timestamp){
    return;
  }
  let date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
  let Y = date.getFullYear() + '-';
  let M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
  let D = lessTen(date.getDate()) + ' ';
  let h = lessTen(date.getHours()) + ':';
  let m = lessTen(date.getMinutes()) + ':';
  let s = lessTen(date.getSeconds());
  return type==='date' ? Y+M+D : Y+M+D+h+m+s;
}

function lessTen(num){
  return num<10 ? '0'+num : num;
}





